package com.zenika.zenbinding.client.converter;

import com.zenika.zenbinding.client.exception.ConverterException;

/**
 * Converter for the Character class.
 * @author Zenika
 */
public class CharacterConverter implements Converter {

	public String fromObjectToString(Object object) throws ConverterException {
		try {
			Character value = (Character) object;
			return value.toString();
		} catch (ClassCastException e) {
			throw new ConverterException();
		}
	}

	public Object fromStringToObject(String string) throws ConverterException {
		if (string.length() > 1) {
			throw new ConverterException();
		}
		Character value = new Character(string.charAt(0));
		return value;
	}

}
